package view.teacher;

import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import base.Session;
import dao.MajorDao;
import dao.TeacherCourseDao;
import model.Major;
import model.Student;
import model.TeacherCourse;

public class MyCourseInterfrm extends JInternalFrame {
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MyCourseInterfrm frame = new MyCourseInterfrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MyCourseInterfrm() {
		setClosable(true);
		setIconifiable(true);
		setTitle("我的课程");
		setBounds(100, 100, 793, 554);
		getContentPane().setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(44, 40, 685, 417);
		getContentPane().add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null},
			},
			new String[] {
				"\u73ED\u7EA7\u540D\u79F0", "\u8BFE\u7A0B\u540D\u79F0", "\u4EBA\u6570"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(2).setPreferredWidth(15);
		scrollPane.setViewportView(table);
		filltable();
	}
	
	private void filltable() {
		DefaultTableModel dtm = (DefaultTableModel) table.getModel();
		dtm.setRowCount(0);
		ArrayList<TeacherCourse> arrayList = TeacherCourseDao.find(Session.id);
		for (TeacherCourse teacherCourse : arrayList) {
			Vector v = new Vector();
			v.add(teacherCourse.getCla_name());
			v.add(teacherCourse.getCou_name());
			v.add(teacherCourse.getCla_number());
			dtm.addRow(v);
		}
	}

}
